package 算法.leetcode.array;

import org.junit.Test;

/**
 * @author lchenglong
 * @date 2020/12/10
 */
public class ValidMountainArray {
    @Test
    public void test() {
        int[] arr = new int[]{3,2,1};
        System.out.println(validMountainArray(arr));
    }
    public boolean validMountainArray(int[] arr) {
        if(arr == null || arr.length < 3) {
            return false;
        }
        int flag = 0;// 0 初始状态 1 上升 2 下降
        int count = 0;
        for(int i=0;i<arr.length-1;i++) {
            if(arr[i+1]>arr[i]) {
                if(flag ==0) {
                    flag++;
                    count++;
                } else if (flag == 2) {
                    return false;
                }
            } else if (arr[i+1] == arr[i]){
                return false;
            } else {
                if(flag == 1) {
                    flag++;
                    count++;
                } else if (flag == 0){
                    return false;
                }
            }
        }
        return count >1;
    }
}
